#!/usr/bin/python
#-*- coding: utf-8 -*-

import sys, cv2
import numpy as np

if __name__=="__main__":
##    if len(sys.argv) != 4:
####        print "--> usage: python showImageExample imageFile"
####        sys.exit(0)

    maxValue = 255
    minValue = 0
    
    bildleft = "cover_left.JPG"
    bildright = "cover_right.JPG"
    bildtop = "cover_top.JPG"

##    #Tobi
    image_left = cv2.imread(bildleft, cv2.CV_LOAD_IMAGE_GRAYSCALE)
##    image_right = cv2.imread(bildright, cv2.CV_LOAD_IMAGE_GRAYSCALE)
##    image_top = cv2.imread(bildtop, cv2.CV_LOAD_IMAGE_GRAYSCALE)
    print type(image_left)
    print image_left.tolist()[0]

    
    #Bild laden
    il = cv2.imread(bildleft, cv2.CV_LOAD_IMAGE_COLOR)
##    image_right = cv2.imread(bildright, cv2.CV_LOAD_IMAGE_COLOR)
##    image_top = cv2.imread(bildtop, cv2.CV_LOAD_IMAGE_COLOR)
##    
    #Graustufe umwandeln
    image_Left_grau  = cv2.cvtColor(il,cv2.COLOR_BGR2GRAY)
##    image_Right_grau = cv2.cvtColor(image_right,cv2.COLOR_BGR2GRAY)
##    image_Top_grau = cv2.cvtColor(image_top,cv2.COLOR_BGR2GRAY)

    print type(image_Left_grau)
    print image_Left_grau.tolist()[0]

    
    #Berechnung
    #iLuminance = (cv2.add(image_Left_grau,image_Top_grau,image_Right_grau))/3
    #ibias = (np.subtract(image_Left_grau, image_Right_grau)/2)+127
    #ibrightness =(bildleft + bildright)/2

    #Tobi
    ibias = image_left.copy()
    for i in range (image_left.shape[0]):
                    for j in range (image_left.shape[1]):
                                    ibias[i][j]=(image_left[i][j]/2 - image_right[i][j] / 2 ) + 127

    #print iLuminance.tolist()[0]
    #print image_Right_grau.tolist()[0]
    #print image_right.tolist()[0]
    
                

    #Fenster erschaffen
    #cv2.namedWindow("Iluminance", cv2.CV_WINDOW_AUTOSIZE)
##    cv2.namedWindow("Ibias", cv2.CV_WINDOW_AUTOSIZE)
    #cv2.namedWindow("Brightness", cv2.CV_WINDOW_AUTOSIZE)

    #Bild anzeigen im Fenster
    #cv2.imshow("Iluminance",iLuminance)
##    cv2.imshow("Ibias",ibias)
    #cv2.imshow("Brightness",image3_grau)

    cv2.waitKey(0)
    cv2.destroyAllWindows()
